import MJCrequest from "./request/index";
import { JavaBASE_URL, TIME_OUT } from "./request/config.js";
import cache from "@/utils/cache.js";
import { ElMessage } from "element-plus";
//java后端请求出口
const javaRequest = new MJCrequest({
  baseURL: JavaBASE_URL,
  timeout: 5000,
  interceptors: {
    requestInterceptor: (config) => {
      console.log("局部请求成功");
      // const token = cache.getCache("token");
      // if (token) {
      //   config.headers.authorization = token;
      // }
      return config;
    },
    requestInterceptorCatch: (config) => {
      console.log("局部请求失败");
      return config;
    },
    responseInterceptor: (res) => {
      console.log("局部的响应成功");
      return res;
    },
    responseInterceptorCatch: (err) => {
      console.log("局部响应失败");
      ElMessage.error(err.data);
      return Promise.reject(err);
    },
  },
});

export default javaRequest;
